import os

import yaml
from common.log import logger
from common.zip_file import zip_files
from common.send_email import SendEmail

def run_case():
    with open("config/config.yaml", mode="r", encoding="utf-8") as f:
        data = yaml.safe_load(f)

    # print(data)
    pytest_allure_cmd = data["pytest_allure_cmd"]
    os.system(pytest_allure_cmd["pytest_cmd"])
    os.system(pytest_allure_cmd["allure_cmd"])

    source = "./allure-report"
    destin = "./allure_report_zip/report.zip"
    zip_files(source, destin)


    try:
        mail_data = data["send_email"]
        send_email = SendEmail(**mail_data)
        send_email.send_email_by_att("自动化测试报告",destin,"自动化测试报告带附件")
    except Exception as e:
        logger.error("邮件发送失败")
        raise e
    else:
        logger.info("邮件发送成功")






if __name__ == '__main__':
    run_case()
